//
//  YHVisitorLoginView.swift
//  WeiBoYH
//
//  Created by yanhui on 2017/1/6.
//  Copyright © 2017年 yanhui. All rights reserved.
//

import UIKit
import SnapKit

//所有的协议必须遵守基协议
@objc protocol YHVisitorLoginViewDelegate: NSObjectProtocol {
    
    //声明登录方法名
  @objc optional func userWillLogin()
    
    //声明注册方法名
    func userWillRegister()
    
}



class YHVisitorLoginView: UIView {

    //声明代理属性
   weak var delegate: YHVisitorLoginViewDelegate?
    
    func updataInfo(imageName: String, title: String, isHome: Bool = false){
        self.circleIcon.image = UIImage(named: imageName)
        self.tipLable.text = title
        if isHome {
            startAnimation()
            
        }else{
            lageHouse.isHidden = true
            maskIcon.isHidden = true
            
        }
    }
    
    
    private func startAnimation(){
        //出示话动画对象
        let animatiom = CABasicAnimation(keyPath: "transform.rotation")
        animatiom.repeatCount = MAXFLOAT
        animatiom.toValue = M_PI * 2
        animatiom.duration = 15
        animatiom.isRemovedOnCompletion = false
        
        circleIcon.layer.add(animatiom, forKey: nil)
        
    }
  
    //自定义访客视图
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
   private func setUpUI(){
        //添加子视图
        addSubview(lageHouse)                                                                                                                                                                   
        addSubview(circleIcon)
        addSubview(tipLable)
        addSubview(loginButton)
        addSubview(registorButton)
        addSubview(maskIcon)
    
    //设置约束
    //大圈圈
    circleIcon.snp.makeConstraints { (make) in
        make.centerY.equalTo(self).offset(-80)
        make.centerX.equalTo(self)
        
    }
    //房子
    lageHouse.snp.makeConstraints { (make) in
        make.center.equalTo(circleIcon)
    }
    //介绍Lable
    tipLable.snp.makeConstraints { (make) in
        make.top.equalTo(self.circleIcon.snp.bottom).offset(10)
        make.centerX.equalTo(self)
    }
    
    //登录按钮
    loginButton.snp.makeConstraints { (make) in
        make.top.equalTo(self.tipLable.snp.bottom).offset(10)
        make.left.equalTo(tipLable)
        make.width.equalTo(80)
    }
    
    //注册按钮
    registorButton.snp.makeConstraints { (make) in
        make.top.equalTo(self.tipLable.snp.bottom).offset(10)
        make.right.equalTo(tipLable)
        make.width.equalTo(80)
    }
    
    //遮罩约束
    maskIcon.snp.makeConstraints { (make) in
        make.center.equalTo(circleIcon)
    }
 
    //设置访客视图的背景颜色
    self.backgroundColor = UIColor(white: 237 / 255.0, alpha: 1)
    
    //添加登录监听方法
    loginButton.addTarget(self, action: #selector(didClickLoginButton), for: .touchUpInside)
    
    //添加注册监听按钮
    registorButton.addTarget(self, action: #selector(didClickRegisterButton), for: .touchUpInside)
 
    }
    
    //点击登录按钮
    func didClickLoginButton(){
        
        delegate?.userWillLogin?()
        
    }
 
    //点击注册按钮
    func didClickRegisterButton(){
       
        delegate?.userWillRegister()
        
    }
 
    //大房子
    lazy var lageHouse: UIImageView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_house"))
    
    //圈圈
    lazy var circleIcon: UIImageView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_smallicon"))
    
    //提示文字
    lazy var tipLable:UILabel = {
        let l = UILabel(text: "关注一些人,回到这里看看有什么惊喜关注一些人,回到这里看看有什么惊喜", fontSize: 14, textColor: UIColor.gray)
        l.preferredMaxLayoutWidth = 220
        l.textAlignment = .center
        return l
    }()
    //登录按钮
    lazy var loginButton: UIButton = {
        let logBtn = UIButton(backImageName: "common_button_white", text: "登录", fontSize: 14, textColor: UIColor.orange)
        return logBtn
    }()
    
    //注册按钮 
    lazy var registorButton: UIButton = {
        let regBtn = UIButton(backImageName: "common_button_white", text: "注册", fontSize: 14, textColor: UIColor.gray)
        return regBtn
    }()
    
    //遮罩
    lazy var maskIcon: UIImageView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_mask_smallicon"))
        
    }
    
    
    



















